home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
More Source
/
Libraries
/
VideoToolbox 95.04.18
/
VideoToolboxSources
/
fp.c
< prev
next >
Wrap
Text File
|
1994-11-15
|
3KB
|
107 lines
/* fp.c
Apple provides a whole bunch of nice functions that are defined in fp.h, but
unfortunately, at present they only exist on the PowerPC. As a stop-gap, until
Apple provides them for 68k machines as well, I've written these 68k-compatible
equivalents. You can safely include this file in all your projects. This file
omits itself if Apple's versions of the functions are available.
At present this file only defines: ldtox80, x80told, and fpclassify. This replaces
the functions formerly provided by the VideoToolbox Sane.c, which I've now discarded.
You may also want to look at the functions defined in IsNan.c, which are very
similar, though not identical to several fp.h functions.
ldtox80 and x80told convert back and forth between long double (any size)
and 10-byte floating point formats. The 10- and 12-byte formats contain exactly
the same information. The 12-byte format, used by the Motorola 68881 and 68040
floating point chips, has an unused 2-byte gap between the exponent and mantissa.
HISTORY:
10/8/94 dgp wrote it.
*/
#include "VideoToolbox.h"
#include <math.h> // ldtox80,x80told,fpclassify
#if !defined(__FP__) // Conditional applies to rest of file.
#if 0
#undef INF
#undef PI
#undef NAN
#include <SANE.h> // x96tox80,x80tox96,extended80,extended96
#else
// if extended80 and extended96 are undefined, change the "#if 0" to "#if 1" above.
void x96tox80(extended96 *,extended80 *);
void x80tox96(extended80 *,extended96 *);
#endif
#include <assert.h>
void ldtox80 (long double *xl,extended80 *x80);
void x80told (extended80 *x80,long double *xl);
long int fpclassify(double x);
void ldtox80 (long double *xl,extended80 *x80)
{
double x;
switch(sizeof(long double)){
case 12:
x96tox80((extended96 *)xl,x80);
return;
case 10:
*x80=*(extended80 *)xl;
return;
default:
switch(sizeof(double)){
case 12:
x=*xl;
x96tox80((extended96 *)&x,x80);
break;
case 10:
*(double *)x80=*xl;
break;
default:
assert(0);
}
}
}
void x80told (extended80 *x80,long double *xl)
{
double x;
switch(sizeof(long double)){
case 12:
x80tox96(x80,(extended96 *)xl);
break;
case 10:
*xl=*(long double *)x80;
break;
default:
switch(sizeof(double)){
case 12:
x80tox96(x80,(extended96 *)&x);
*xl=x;
break;
case 10:
*xl=*(double *)x80;
break;
default:
assert(0);
}
}
}
pascal void MyClassExtended(extended80 *,short *) = { 0x3F3C,0x001C,0xA9EB };
long int fpclassify(double x)
{
short n;
extended80 x80;
long double xl;
xl=x;
ldtox80(&xl,&x80);
MyClassExtended(&x80,&n);
return n;
}
#endif